package com.lap.auth.adapter.driven.web.role;

import com.lap.auth.application.role.RoleDataScopeAppService;
import com.lap.auth.application.role.command.CreateDataScopeCmd;
import com.lap.auth.application.role.dto.RoleDataScopeDto;
import com.lap.watchdog.starter.annotation.RepeatSubmit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "角色授权数据权限", description = "提供角色数据权限授权")
@RequiredArgsConstructor
@RestController
@RequestMapping("api/v1/roles")
public class RoleDataScopeController {

  private final RoleDataScopeAppService roleDataScopeAppService;

  @Operation(summary = "获取角色数据权限")
  @GetMapping("{roleId}/data-scope")
  public RoleDataScopeDto getRoleDataScopes(@PathVariable Integer roleId) {
    return roleDataScopeAppService.getRoleDataScopes(roleId);
  }

  @Operation(summary = "授权角色数据权限")
  @RepeatSubmit
  @PutMapping("{roleId}/data-scope")
  public void updateDataScope(@PathVariable Integer roleId, @RequestBody CreateDataScopeCmd cmd) {
    roleDataScopeAppService.saveDataScope(roleId, cmd);
  }
}
